﻿using ReactiveUI;
using ReactiveUI.Fody.Helpers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Common.ViewModels
{
    /// <summary>
    /// 工位工作信息
    /// </summary>
    public class StationWorkInfo : BaseViewModel
    {
        [Reactive] public WorkStation WorkStation { get; set; }

        [Reactive] public StationWorkState StationWorkState { get; set; } = StationWorkState.None;

        private DateTime? m_开始工作时间;

        /// <summary>
        /// 开始工作时间
        /// </summary>
        public DateTime? 开始工作时间
        {
            get => m_开始工作时间;
            set
            {
                if (m_开始工作时间 == value)
                {
                    return;
                }
                m_开始工作时间 = value;
                this.RaisePropertyChanged();
            }
        }

        /// <summary>
        /// 获取剩余工作时间(系统用)
        /// </summary>
        /// <returns></returns>
        public TimeSpan Get剩余工作时间()
        {
            if (WorkStation == null)
            {
                return TimeSpan.FromDays(800);
            }

            if (开始工作时间 == null)
            {
                return TimeSpan.FromDays(800);
            }
            var ts = DateTime.Now - 开始工作时间.Value - TimeSpan.FromMilliseconds(WorkStation.池子.工位类型.Time);
            return ts;
        }
    }

    /// <summary>
    /// 状态
    /// </summary>
    public enum StationWorkState
    {
        /// <summary>
        /// 未知状态
        /// </summary>
        None,

        /// <summary>
        /// 在来的路上
        /// </summary>
        Loading,

        /// <summary>
        /// 正在工作
        /// </summary>
        Work,

        /// <summary>
        /// 工作完成(等待取走)
        /// </summary>
        Finished,
    }
}
